// 批量合并PT到优先队列
void PriorityQueue::Merge(const vector<PT>& new_pts)
{
    if (new_pts.empty()) return;
    
    // 如果主队列为空，直接赋值
    if (priority.empty()) {
        priority = new_pts;
        return;
    }
    
    // 使用归并排序思想高效合并两个有序数组
    vector<PT> merged;
    merged.reserve(priority.size() + new_pts.size());
    
    size_t i = 0, j = 0;
    while (i < priority.size() && j < new_pts.size()) {
        if (priority[i].prob >= new_pts[j].prob) {
            merged.push_back(priority[i++]);
        } else {
            merged.push_back(new_pts[j++]);
        }
    }
    
    // 添加剩余元素
    while (i < priority.size()) {
        merged.push_back(priority[i++]);
    }
    while (j < new_pts.size()) {
        merged.push_back(new_pts[j++]);
    }
    
    priority = std::move(merged);
}

// 并行PT处理函数
void PriorityQueue::PopNextBatch(int batch_size)
{
    batch_size = min(batch_size, (int)priority.size());
    if (batch_size == 0) return;

    // 1. 取出前batch_size个PT
    vector<PT> batch_pts(priority.begin(), priority.begin() + batch_size);
    priority.erase(priority.begin(), priority.begin() + batch_size);

    // 2. 并行处理猜测生成
    #pragma omp parallel for schedule(dynamic)
    for (int i = 0; i < batch_pts.size(); i++) {
        Generate_omp(batch_pts[i]);
        //  
    }

    // 3. 批量生成新PT
    vector<PT> all_pts;
    for (int i = 0; i < batch_pts.size(); i++) {
        vector<PT> new_pts = batch_pts[i].NewPTs();
        for (auto &pt : new_pts) {
            CalProb(pt); 
            all_pts.push_back(std::move(pt));
        }
    }

    // 4. 排序新PT
    sort(all_pts.begin(), all_pts.end(), [](const PT& a, const PT& b) { return a.prob > b.prob; });

    // 5. 批量合并到主队列
    Merge(all_pts);
}